package service.subject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.common.BaseMapper;
import com.common.BaseService;
import com.common.CommonUtil;

import beans.subject.subsetquestionsubject;
import mapper.subject.subsetquestionsubjectMapper;


@Service
@Transactional
public class SubSetQuestionSubjectImpl<T> extends BaseService<T>{

	@Autowired
	private subsetquestionsubjectMapper<T> _subsetquestionsubjectMapper;

	@Override
	public BaseMapper<T> getMapper() {
		return _subsetquestionsubjectMapper;
	}

	public List<T> queryByIds(String[] ids) {
		return _subsetquestionsubjectMapper.queryByIds(ids);
	}

	public List<Map> queryCountBysqid(List<String> ids) {
		return _subsetquestionsubjectMapper.queryCountBysqid(ids);
	}

	/**
	 * 根据专题id获取题目
	 * @param id
	 * @return
	 */
	public List<subsetquestionsubject> getBySubSetId(String sqid) {
		return _subsetquestionsubjectMapper.getBySubSetId(sqid);
	}

	public void save(String sqid, String[] ids) {
		_subsetquestionsubjectMapper.delSqSubject(sqid);
		List<Map> list = new ArrayList<>();
		if(ids.length>0){
			for(String s : ids){
				if(CommonUtil.isNullObject(s))continue;
				Map m = new HashMap();
				m.put("id", UUID.randomUUID().toString());
				m.put("sqid", sqid);
				m.put("subid", s);
				list.add(m);
			}
			if(list.size()>0)
				_subsetquestionsubjectMapper.saveSqSubject(list);
		}
	}
}